package com.wondertek.poms.dao.po;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.wondertek.poms.common.constant.CurrentUser;
import com.wondertek.poms.dao.pojo.EquityNodePojo;
import lombok.Data;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.Proxy;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

@Data
@Entity
@Table(name = "EQUITY_TREE")
@DynamicUpdate
@DynamicInsert
@Proxy(lazy = false)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class EquityTree implements Serializable {

    private static final long serialVersionUID = 7413415993082605864L;

    /**
     *  权益树id
     */
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "EQUITY_TREE_SEQ")
    @SequenceGenerator(name = "EQUITY_TREE_SEQ", allocationSize = 1, sequenceName = "EQUITY_TREE_SEQ")
    private Long id;

    /**
     *  权益树名称
     */
    @Column(name = "EQUITY_TREE_NAME")
    private String equityTreeName;

    /**
     *  权益树别名
     */
    @Column(name = "ALIAS")
    private String alias;

    /**
     *  权益树深度
     */
    @Column(name = "EQUITY_TREE_DEPTH")
    private Integer equityTreeDepth;

    /**
     *  0:已发布 1：撤回  2待发布
     */
    @Column(name = "ACTIVES_STATUS")
    private String activeStatus;

    /**
     *   创建时间
     */
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Column(name="CREATE_TIME")
    private Date createTime;

    /**
     *  创建人
     */
    @Column(name = "AUTHOR")
    private String author;

    @Transient
    private List<EquityNodePojo> nodes=new LinkedList<EquityNodePojo>();

    public static void putTimeAndUser(EquityTree equityTree) {
        equityTree.setAuthor(CurrentUser.currUserName());
        equityTree.setCreateTime(new Date());
    }
}
